//
//  LGHomeViewController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/14.
//

#import "LGHomeViewController.h"
//二维码
#import "LGQRCodeViewController.h"
//搜索患者
#import "LGPatientSearchController.h"
//个人资料
#import "LGPersionalDataController.h"
//运动方案
#import "LGRecoverySportsController.h"
//接诊设置
#import "LGReceptionSettingController.h"
//管理照护计划
#import "LGCarePlanManageController.h"
//随访审核
#import "LGLungFollowAuditController.h"
//设备发货
#import "LGDeviceSendViewController.h"
//批量添加随访计划
#import "LGLungFollowTemplateController.h"
//订单确认
#import "LGOrderConfirmController.h"
//设备领用
#import "LGDeviceManagerController.h"
//订单退款
#import "LGOrderRefundController.h"
//服务包到期
#import "LGServiceExpiresController.h"
//全部日程
#import "LGFullScheduleController.h"
//添加随访记录
#import "LGDiseaseOverviewController.h"//病情概览
#import "LGPatientNumberController.h"//输入患者登记号

//报告上传
#import "LGUploadReportPatientController.h"

//患者详情 - 圆荷健康
#import "LGPatientDetailController_YHJK.h"
#import "LGPatientDetailController2.h"

//运动康复
#import "LGPatientSportsController.h"
//聊天页面
#import "TUIC2CChatViewController.h"
#import "TUIChatConversationModel.h"

//咨询订单详情
#import "LGOrderDetailController.h"
//常规门诊 、慢病复查
#import "LGNormalClinicController.h"
//电话咨询
#import "LGMedicineBallPhoneController.h"
#import "TUIFoldListViewController.h"
#import "TUIConversationCell.h"
#import "TUICore.h"
#import "TUIDefine.h"
#import "TUIThemeManager.h"
#import "TUIConversationListDataProvider.h"
#import "TUIConversationListBaseDataProvider.h"
#import "TUIConversationListControllerListener.h"
#import "TUIConversationCellData.h"
#import "TUIDefine.h"
#import <ImSDK_Plus/V2TIMManager.h>
#import "LGHomeHeaderView.h"
#import "LGHomeViewCell.h"
#import "LGVersionUpdateView.h"
#import "LGBottomShadowView.h"
#import "LGHomeOrganView.h"
//测试
#import "LGReportingCenterController.h"
#import "LGInspectReportDetailController.h"
#import "LGHomeMonitoringController.h"
#import "LGSportsEvaRecordController.h"
#import "LGAddDoctorAdviceController.h"
#import "LGMedicineManageController.h"
#import "LGFollowAdviceRecordController.h"
#import "LGMedicineBallHomeController.h"
#import "LGMedicineBallDetailController.h"
#import "LGPatientCarePlanController.h"
#import "LGMedicineBallScreenView.h"
#import "LGSelectDateView.h"
#import "ViewController.h"
#import "LGDeviceDeliverView.h"
#import "LGDeviceManagerTabController.h"
@interface LGHomeViewController ()<UITableViewDataSource,UITableViewDelegate,LGHomeHeaderViewDelegate,V2TIMAdvancedMsgListener,TUIConversationListDataProviderDelegate,LGHomeOrganViewDelegate>
@property (nonatomic, strong) TUIConversationListBaseDataProvider *dataProvider;
/**   */
@property (nonatomic , strong)LGBottomShadowView *shadowView;
/**   */
@property (nonatomic , strong)UIImageView *baseView;
/**   */
@property (nonatomic , strong)LGHomeHeaderView *headView;
/**   */
@property (nonatomic , strong)LGHomeOrganView *organView;
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)NSArray *dataArray;
/**   */
@property (nonatomic , copy)NSString *addFollowKey;
/**   */
@property (nonatomic , copy)NSString *currentDate;
/**   */
@property (nonatomic , strong)NSDateFormatter *formatter;

@end

@implementation LGHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.addFollowKey = @"";
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    self.currentDate = [self.formatter stringFromDate:[NSDate date]];
    [self.view addSubview:self.baseView];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.shadowView];
    [self emptyViewWithSuperView:self.tableView frame:CGRectMake(0, kMaxY(self.headView.frame), Screen_W, Screen_H-tabBarHeight-kMaxY(self.headView.frame))];
    self.emptyView.backgroundColor = [UIColor whiteColor];
    [self requestVersionData];//版本更新
    //咨询消息监听
    [self.dataProvider loadNexPageConversations];
    [self onRecvNewMessage:nil];
    [[V2TIMManager sharedInstance] addAdvancedMsgListener:self];
    [self showUnreadCount];
    [[ObjectTool mainWindow] addSubview:self.organView];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self viewWillAppearAction];
}

-(void)viewWillAppearAction{
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/workbench/index" parameters:@{@"today":self.currentDate} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        [self.tableView.mj_header endRefreshing];
        if(code == 200){
            self.addFollowKey = LGNSString(returnData[@"add_followup_key"]);
            NSString *roleType = LGNSString(returnData[@"doctor"][@"role_type_val"]);
            [[NSUserDefaults standardUserDefaults] setValue:roleType forKey:@"roleId"];
            [[NSUserDefaults standardUserDefaults] setValue:LGNSString(returnData[@"doctor"][@"role_type_patientval"]) forKey:@"patientval"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            self.organView.dataArray = returnData[@"organs"][@"organs"];
            self.headView.organArray = returnData[@"organs"][@"organs"];
            self.headView.doctorDic = returnData[@"doctor"];
            self.headView.itemArray = returnData[@"button"];
            self.headView.scheduleArray = returnData[@"schedule"];
            CGFloat height = viewPix(60)*(floor(self.headView.itemArray.count/4.5)+1)+viewPix(233);
            self.headView.frame = CGRectMake(0, 0, Screen_W, statusBarHeight+height);
            self.tableView.tableHeaderView = self.headView;
            self.emptyView.frame = CGRectMake(0, kMaxY(self.headView.frame), Screen_W, Screen_H-tabBarHeight-kMaxY(self.headView.frame));
            self.dataArray = returnData[@"list"];
            [self.tableView reloadData];
        }
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:LGEmptyPicName2 content:@"暂无数据" offset:viewPix(50)];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        [self.tableView.mj_header endRefreshing];
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:LGEmptyPicName2 content:@"暂无数据" offset:viewPix(50)];
        }
    }];
}

//请求版本号
-(void)requestVersionData{
    [RequestUtil withPOST:@"/doctor/my.about/version" parameters:@{@"client":@"ios",@"client_name":@"doctor"} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            NSString *version = LGNSString(returnData[@"version"]);
            NSArray  *newArray = [version componentsSeparatedByString:@"."];
            NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
            NSArray *currenArray = [currentVersion componentsSeparatedByString:@"."];
            BOOL needUpdate = NO;
            
            for (NSInteger i=0; i<newArray.count; i++) {
                if(i<currenArray.count){
                    if ([currenArray[i] integerValue] < [newArray[i] integerValue]) {
                        needUpdate = YES;
                        break;
                    }else if ([currenArray[i] integerValue] > [newArray[i] integerValue]){
                        needUpdate = NO;
                        break;
                    }
                }else{
                    needUpdate = YES;
                }
            }
            if(needUpdate == YES){
                LGVersionUpdateView *updateView = [[LGVersionUpdateView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
                updateView.newerVersion = version;
                [[UIApplication sharedApplication].keyWindow addSubview:updateView];
                updateView.updateVersionAction = ^{
                    //更新版本
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:AppLink] options:@{} completionHandler:nil];
                };
            }
        }
    } error:^(NSError *error) {
        
    }];
}

//选择机构
-(void)selectOrganAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.selected == YES) {
        [self.organView showOrganViewAnimation];
    }else{
        [self.organView hiddeOrganViewAnimation];
    }
}

//更换机构
-(void)swichOrganAction:(NSDictionary *)dataDic{
    self.headView.organBtn.selected = NO;
    [RequestUtil withPOST:@"/doctor/workbench/organSwitch" parameters:@{@"level_id":LGNSString(dataDic[@"level_id"])} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            [self requestData];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshPatientTable" object:nil];
        }else{
            [TooltipView showMessage:message offset:0];
        }
    } error:^(NSError *error) {
        
    }];
}

//关闭机构弹框
-(void)closeOrganViewAction{
    self.headView.organBtn.selected = NO;
    [self.organView hiddeOrganViewAnimation];
}

//查看个人信息
-(void)checkDoctorInfoAction{
    LGPersionalDataController *controller = [[LGPersionalDataController alloc]init];
    controller.userId = kUserId;
    [self.navigationController pushViewController:controller animated:YES];
}
//搜索
-(void)searchPatientAction{
    LGPatientSearchController *controller = [[LGPatientSearchController alloc]init];
    [self.navigationController pushViewController:controller animated:YES];
}
//二维码
-(void)checkQRCodeAction{
    LGQRCodeViewController *controller = [[LGQRCodeViewController alloc]init];
    controller.dataDic = self.headView.doctorDic;
    [self.navigationController pushViewController:controller animated:YES];
}

//添加咨询记录--添加随访
-(void)addConsultRecordAction{
    if(!_addFollowKey || _addFollowKey.length == 0){
        [self requestData];
        return;
    }
//    LGAddEditFollowUpController *controller = [[LGAddEditFollowUpController alloc]init];
//    controller.followKey = self.addFollowKey;
//    controller.canSearch = YES;
//    [self.navigationController pushViewController:controller animated:YES];
    LGPatientNumberController *controller = [[LGPatientNumberController alloc]init];
    controller.followDate = self.currentDate;
    [self.navigationController pushViewController:controller animated:YES];
}

//item按钮点击事件
-(void)itemButtonTouched:(NSString *)code{
    if([code isEqualToString:@"1"]){
        //运动方案
        LGRecoverySportsController *controller = [[LGRecoverySportsController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"2"]){
        //入院管理
        LGMedicineBallHomeController *controller = [[LGMedicineBallHomeController alloc]init];
        controller.datasource = @"";
        [self.navigationController pushViewController:controller animated:YES];

    }else if ([code isEqualToString:@"3"]){
        //接诊设置
        LGReceptionSettingController *controller = [[LGReceptionSettingController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"4"]){
        //药球管理 LGMedicineBallDetailController 、 LGMedicineBallHomeController
        LGMedicineBallHomeController *controller = [[LGMedicineBallHomeController alloc]init];
        controller.datasource = @"dcb";
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"5"]){
        //管理照护计划
        LGCarePlanManageController *controller = [[LGCarePlanManageController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"6"]){
        //设备发货
        LGDeviceSendViewController *controller = [[LGDeviceSendViewController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"7"]){
        //癌症 - 批量发送随访计划
        LGLungFollowTemplateController *controller = [[LGLungFollowTemplateController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"8"]){
        //癌症 - 随访审核
        LGLungFollowAuditController *controller = [[LGLungFollowAuditController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"9"]){
        //订单确认
        LGOrderConfirmController *controller = [[LGOrderConfirmController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"10"]){
        //设备领用
        LGDeviceManagerController *controller = [[LGDeviceManagerController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"11"]){
        //订单退款
        LGOrderRefundController *controller = [[LGOrderRefundController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"12"]){
        //服务包到期
        LGServiceExpiresController *controller = [[LGServiceExpiresController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"13"]){
        //报告上传
        LGUploadReportPatientController *controller = [[LGUploadReportPatientController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([code isEqualToString:@"全部日程"]){
        //全部日程
        LGFullScheduleController *controller = [[LGFullScheduleController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }
}

//查看其他日期数据
-(void)checkScheduleData:(NSString *)dateString{
    self.currentDate = dateString;
    [self requestData];
}

//弹框提示
-(void)alertTipAction:(NSDictionary *)alertDic{
    __weak typeof(self) weakSelf = self;
    [LGAlertTool alertWithTitle:@"提示" content:LGNSString(alertDic[@"confirm"]) sureAction:^{
        [RequestUtil withPOST:LGNSString(alertDic[@"apiUrl"]) parameters:@{@"updateparams":alertDic[@"params"]} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
            if(code == 200){
                [weakSelf requestData];
            }else{
                [TooltipView showMessage:message offset:0];
            }
        } error:^(NSError *error) {
            [TooltipView showMessage:@"保存失败，请重试" offset:0];
        }];
    }];
}

//直接请求
-(void)touchSwipeAction:(NSDictionary *)dataDic{
    [RequestUtil withPOST:LGNSString(dataDic[@"apiUrl"]) parameters:@{@"updateparams":dataDic[@"params"]} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            [self requestData];
        }else{
            [TooltipView showMessage:message offset:0];
        }
    } error:^(NSError *error) {
        [TooltipView showMessage:@"保存失败，请重试" offset:0];
    }];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGHomeViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dataDic = self.dataArray[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *tempDic = self.dataArray[indexPath.row];
    NSString *type = LGNSString(tempDic[@"type"]);
    //diseaseCode：1-房颤 、 2-肺癌 、 3、6-肺结节 、 4-食管癌 、5-房颤
    NSString *diseaseCode = LGNSString(tempDic[@"disease_code"]);
    if([type isEqualToString:@"cept"]){
        //心肺运动
        LGPatientSportsController *controller = [[LGPatientSportsController alloc]init];
        controller.patientid = LGNSString(tempDic[@"patient_id"]);
        controller.diseaseCode = diseaseCode;
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([type isEqualToString:@"video"] ){
        //视频咨询 --
        TUIChatConversationModel *model = [[TUIChatConversationModel alloc]init];
        model.title = LGNSString(tempDic[@"realname"]);
        model.userID = LGNSString(tempDic[@"member_im_id"]);
        TUIC2CChatViewController *controller = [[TUIC2CChatViewController alloc]init];
        controller.appointment_id = LGNSString(tempDic[@"appointment_id"]);
        controller.doctorid = LGNSString(tempDic[@"system_user_id"]);
        controller.roomKey = [NSString stringWithFormat:@"%@|||%@",XGUserId,model.userID];
        controller.needCustomeData = YES;
        [controller setConversationData:model];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if (![[NSObject appType:diseaseCode] isEqualToString:@"YHJK"] && ([type isEqualToString:@"visit"]||[type isEqualToString:@"followup"])){
        //心律助手、心康管家 -- 线下复查、常规门诊
        LGNormalClinicController *controller = [[LGNormalClinicController alloc]init];
        controller.patientid = LGNSString(tempDic[@"patient_id"]);
        controller.diseaseCode = diseaseCode;
        controller.levelid = LGNSString(tempDic[@"level_id"]);
        controller.visit_id = LGNSString(tempDic[@"followup_key"]);
        controller.visit_date = LGNSString(tempDic[@"today"]);
        controller.title = LGNSString(tempDic[@"title"]);
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([type isEqualToString:@"phone"]){
        //电话咨询
        LGMedicineBallPhoneController *controller = [[LGMedicineBallPhoneController alloc]init];
        controller.patientid = LGNSString(tempDic[@"patient_id"]);
        controller.planid = LGNSString(tempDic[@"appointment_id"]);
        controller.type = @"appoint";
        [self.navigationController pushViewController:controller animated:YES];
    }
}

-(UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSMutableArray *actionArray = [NSMutableArray array];
    NSArray *buttonArray = self.dataArray[indexPath.row][@"buttonList"];
    __block NSString *patientid = LGNSString(self.dataArray[indexPath.row][@"patient_id"]);
    __block NSString *diseaseCode = LGNSString(self.dataArray[indexPath.row][@"disease_code"]);
    __block NSString *levelid = LGNSString(self.dataArray[indexPath.row][@"level_id"]);
    __weak typeof(self) weakSelf = self;
    for (NSInteger i=0; i<buttonArray.count; i++) {
        __block NSDictionary *tempDic = buttonArray[i];
        __block NSString *type = LGNSString(tempDic[@"type"]);
        NSString *title = [LGNSString(tempDic[@"title"]) stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
        UIContextualAction *action = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:title handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
            [tableView setEditing:NO animated:YES];
            if([type isEqualToString:@"pinfo"]){
                //患者详情
                //市一慢阻肺、哮喘
                if ([diseaseCode isEqualToString:@"24"] || [diseaseCode isEqualToString:@"25"]) {
                    LGPatientDetailController2 *controller = [[LGPatientDetailController2 alloc]init];
                    controller.diseaseCode = diseaseCode;
                    controller.patientid = patientid;
                    controller.levelid = levelid;
                    [self.navigationController pushViewController:controller animated:YES];
                }else{
                    LGPatientDetailController_YHJK *controller = [[LGPatientDetailController_YHJK alloc]init];
                    controller.diseaseCode = diseaseCode;
                    controller.patientid = patientid;
                    controller.levelid = levelid;
                    [self.navigationController pushViewController:controller animated:YES];
                }
                
            }else{
                //操作
                if(LGNSString(tempDic[@"confirm"]).length>0){
                    //有弹框提示
                    [weakSelf alertTipAction:tempDic];
                }else{
                    //无弹框提示
                    [weakSelf touchSwipeAction:tempDic];
                }
            }
        }];
        action.backgroundColor = [UIColor colorWithString:tempDic[@"color"]];
        [actionArray insertObject:action atIndex:0];
    }
    UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:actionArray];
    actions.performsFirstActionWithFullSwipe = NO;
    return actions;
}


#pragma mark
#pragma mark ====> 消息监听
-(void)showUnreadCount{
    if (!NSThread.isMainThread) {
        __weak typeof(self) weakSelf = self;
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf showUnreadCount];
        });
        return;
    }
    
    NSInteger count = 0;
    for (TUIConversationCellData *data in self.dataProvider.conversationList) {
        count += data.unreadCount;
    }
    if (count>0) {
        [self.tabBarController.tabBar showBadgeOnItmIndex:1 withContent:[NSString stringWithFormat:@"%ld",count]];
    }else{
        [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
    }
}

-(void)onRecvNewMessage:(V2TIMMessage *)msg{
    [self performSelector:@selector(showUnreadCount) withObject:nil afterDelay:1];
}

- (NSString *)getConversationDisplayString:(V2TIMConversation *)conversation{
    [self showUnreadCount];
    return nil;
}

- (void)insertConversationsAtIndexPaths:(NSArray *)indexPaths {
    [self showUnreadCount];
}

- (void)reloadConversationsAtIndexPaths:(NSArray *)indexPaths {
    [self showUnreadCount];
}

- (void)deleteConversationAtIndexPaths:(NSArray *)indexPaths {
    [self showUnreadCount];
}

- (void)reloadAllConversations{
    [self showUnreadCount];
}


- (void)dealloc{
    [NSNotificationCenter.defaultCenter removeObserver:self];
}


#pragma mark
#pragma mark ====> 创建控件
-(TUIConversationListBaseDataProvider *)dataProvider{
    if (!_dataProvider) {
        _dataProvider = [[TUIConversationListDataProvider alloc] init];
        _dataProvider.delegate = self;
    }
    return _dataProvider;
}

-(UIImageView *)baseView{
    if(!_baseView){
        _baseView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"首页-背景"]];
        _baseView.frame = CGRectMake(0, 0, Screen_W, viewPix(450));
        _baseView.userInteractionEnabled = YES;
    }
    return _baseView;
}

-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-tabBarHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGHomeViewCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = self.headView;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestData)];
    }
    return _tableView;
}

-(LGHomeHeaderView *)headView{
    if(!_headView){
        _headView = [[LGHomeHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, statusBarHeight+viewPix(296))];
        _headView.backgroundColor = [UIColor clearColor];
        _headView.delegate = self;
        [_headView.organBtn addTarget:self action:@selector(selectOrganAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _headView;
}

-(LGBottomShadowView *)shadowView{
    if (!_shadowView) {
        _shadowView = [[LGBottomShadowView alloc]initWithFrame:CGRectMake(0, Screen_H-tabBarHeight-20, Screen_W, 20)];
    }
    return _shadowView ;
}

-(LGHomeOrganView *)organView{
    if(!_organView){
        _organView = [[LGHomeOrganView alloc]initWithFrame:CGRectMake(0, statusBarHeight+viewPix(32), Screen_W, Screen_H-statusBarHeight)];
        [_organView.closeBtn addTarget:self action:@selector(closeOrganViewAction) forControlEvents:UIControlEventTouchUpInside];
        _organView.delegate = self;
        _organView.hidden = YES;
    }
    return _organView;
}

-(NSDateFormatter *)formatter{
    if(!_formatter){
        _formatter = [[NSDateFormatter alloc]init];
        _formatter.dateFormat = @"yyyy-MM-dd";
    }
    return _formatter;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
